package com.example.administrator.myapplication;

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    EditText mEtData;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mEtData = findViewById(R.id.et_data);
    }

    public void save(View view) {
        String data = mEtData.getText().toString();
        SharedPreferences sp = getSharedPreferences("data.sp",MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("name",data);
        editor.commit();
    }

    public void read(View view) {
        SharedPreferences sp = getSharedPreferences("data.sp",MODE_PRIVATE);
        String name = sp.getString("name","");
        TextView tvData = findViewById(R.id.tv_data);
        tvData.setText(name);
    }
}
